package com.netease.nim.demo.session.announcement;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.LinearLayout;

import com.netease.nim.demo.team.model.Announcement;
import com.shwread.android.qysw10000227.R;

import java.util.List;

/**
 * 群公告弹出框
 *
 * Created by huangjun on 2015/3/24.
 */
public class AnnouncementDialog extends Dialog {

    private Context context;

    private List<Announcement> data;
    private View placeHolder;
    private AnnouncementView announcementView;
    private AnnouncementView.AnnouncementOnClickListener listener;
    private int maxPageCount;

    // view
    private ViewPager vp;
    private LinearLayout indicator;

    public AnnouncementDialog(Context context, List<Announcement> data,
                              int maxPageCount, AnnouncementView.AnnouncementOnClickListener
            listener) {
        super(context, R.style.transparent_dialog_style);
        this.context = context;
        this.data = data;
        this.maxPageCount = maxPageCount;
        this.listener = listener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.team_message_announce_dialog);

        init();
    }

    private void init() {
        this.placeHolder = findViewById(R.id.announce_placeholder);
        this.vp = (ViewPager) findViewById(R.id.annourcement_vp);
        this.indicator = (LinearLayout) findViewById(R.id.annourcement_indicator);

        if (announcementView == null) {
            announcementView = new AnnouncementView(context, vp, indicator,
                    data, listener, maxPageCount);
        }

        placeHolder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }

    @Override
    public void show() {
        super.show();
        announcementView.showAnnouncement();
    }
}
